<div class="content-body">
    <div class="layui-form" lay-filter="LAY-points-rule-form" style="padding: 20px 30px 0 0;">
        <input type="hidden" name="id" value="<?php echo isset($rule) ? $rule->id : ''; ?>">
        
        <div class="layui-form-item">
            <label class="layui-form-label">规则名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="<?php echo isset($rule) ? $rule->name : ''; ?>" lay-verify="required" placeholder="请输入规则名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">规则类型</label>
            <div class="layui-input-block">
                <select name="type" lay-verify="required" lay-filter="ruleType">
                    <option value="">请选择规则类型</option>
                    <option value="consume" <?php echo isset($rule) && $rule->type == 'consume' ? 'selected' : ''; ?>>消费赠送</option>
                    <option value="sign" <?php echo isset($rule) && $rule->type == 'sign' ? 'selected' : ''; ?>>签到赠送</option>
                    <option value="register" <?php echo isset($rule) && $rule->type == 'register' ? 'selected' : ''; ?>>注册赠送</option>
                    <option value="birthday" <?php echo isset($rule) && $rule->type == 'birthday' ? 'selected' : ''; ?>>生日赠送</option>
                </select>
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">积分值</label>
            <div class="layui-input-block">
                <input type="number" name="points" value="<?php echo isset($rule) ? $rule->points : ''; ?>" lay-verify="required|number" placeholder="请输入积分值" autocomplete="off" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item" id="condition-item" style="display: none;">
            <label class="layui-form-label">消费金额</label>
            <div class="layui-input-block">
                <input type="number" name="condition" value="<?php echo isset($rule) ? $rule->condition : ''; ?>" placeholder="请输入消费满多少元可获得积分" autocomplete="off" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">规则说明</label>
            <div class="layui-input-block">
                <textarea name="description" placeholder="请输入规则说明" class="layui-textarea"><?php echo isset($rule) ? $rule->description : ''; ?></textarea>
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" <?php echo !isset($rule) || $rule->status == 1 ? 'checked' : ''; ?>>
                <input type="radio" name="status" value="0" title="禁用" <?php echo isset($rule) && $rule->status == 0 ? 'checked' : ''; ?>>
            </div>
        </div>
        
        <div class="layui-form-item layui-hide">
            <button class="layui-btn" lay-submit lay-filter="LAY-points-rule-submit" id="LAY-points-rule-submit">提交</button>
        </div>
    </div>
</div>

<script>
layui.use(['form'], function(){
    var $ = layui.$
    ,form = layui.form;
    
    //监听规则类型选择
    form.on('select(ruleType)', function(data){
        var value = data.value;
        var conditionItem = $('#condition-item');
        
        if(value === 'consume') {
            conditionItem.show();
            $('input[name="condition"]').attr('lay-verify', 'required|number');
        } else {
            conditionItem.hide();
            $('input[name="condition"]').removeAttr('lay-verify');
        }
    });
    
    //初始化表单
    var type = $('select[name="type"]').val();
    if(type === 'consume') {
        $('#condition-item').show();
        $('input[name="condition"]').attr('lay-verify', 'required|number');
    }
});
</script> 